
// @ts-nocheck
// _selft _blank
function open(path, name = '_self'){
    if( path === undefined ) return;
    window.open(`${window.location.origin}/${path}`, name)
}

//解析url上的参数
function getUrlParams(keys, origin = location.href){
    let result = {}
    const matchArray = origin.match(/[\w]+=([\w]*)/g)
    if( Array.isArray(matchArray) ){
        matchArray.forEach(item=>{
            const data = item.match(/[\w]+/g)
            if( data ){
                const [key, value] = data
                result[key] =  value && value !== 'undefined' ? value : ''
            }
        })
    }
    if( typeof keys === 'string' ){
        return result.hasOwnProperty(keys) ?  result[keys] : undefined;
    }
    if( Array.isArray(keys) ){
        return keys.map(key=> result.hasOwnProperty(key) ?  result[key] : undefined)
    }
    return result
}

const getOS = () => {
    let sUserAgent = navigator.userAgent;
    let isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
    let isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
    let systemInfo = ""
    if (isMac) systemInfo = "Mac";
    let isUnix = (navigator.platform == "X11") && !isWin && !isMac;
    if (isUnix) systemInfo = "Unix";
    let isLinux = (String(navigator.platform).indexOf("Linux") > -1);
    if (isLinux) systemInfo = "Linux";
    if (isWin) {
        let isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
        if (isWin2K) systemInfo = "Win2000";
        let isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
        if (isWinXP) systemInfo = "WinXP";
        let isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
        if (isWin2003) systemInfo = "Win2003";
        let isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
        if (isWinVista) systemInfo = "WinVista";
        let isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
        if (isWin7) systemInfo = "Win7";
        let isWin10 = sUserAgent.indexOf("Windows NT 10") > -1 || sUserAgent.indexOf("Windows 10") > -1;
        if (isWin10) systemInfo = "Win10";
    }
    systemInfo = "other";
    return {
        isWin,
        systemInfo
    }
}

export {
    open,
    getUrlParams,
    getOS,
}